package servlets;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.Solicituddcc;
import dao.interfaces.SolicituddccDAO;
import factory.Factory;

/**
 * Servlet implementation class SGenerarSolicitudDCC
 */
@WebServlet("/SGenerarSolicitudDCC")
public class SGenerarSolicitudDCC extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Date d = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		String codcli = request.getParameter("cli");
		String codcur = request.getParameter("cur");
		int nropart = Integer.parseInt(request.getParameter("part"));
		String hini = request.getParameter("hini");
		String hfin = request.getParameter("hfin");
		String frec = request.getParameter("frec");
		
		String fecha = sdf.format(d);
		
		Factory f = Factory.obtenerTipo(Factory.MySql);
		SolicituddccDAO sdao = f.obtenerSolicituddccDAO();
		
		String nro = sdao.obtenerCodigo();
		
		Solicituddcc sdcc = new Solicituddcc(nro, fecha, codcli, codcur, nropart, hini, hfin, frec, 5);
		
		int salida = sdao.registrarSolicitud(sdcc);
		System.out.println("[SMANT SOLI] registro: "+salida);
		
		request.getRequestDispatcher("frm_generar_solicituddcc.jsp").forward(request, response);
	}

}
